<?php

	include_once("./global.php");
	session_start();
	if($_SESSION[id]){	
		$url = $_SERVER['REQUEST_URI'];
		$url_arr = parse_url($url);
		parse_str($url_arr['query'],$url_arr);
		$url_page = $url_arr[page];
		$url_keyword = $url_arr[kw];
		$url_category = $url_arr[ca];
		
		if($url_keyword){		
			$where = "A_Categoryid = '".$url_keyword."'";
			if($url_category == ''){
				$order = 'A_Appid';
				$condition = new Condition($where,$order);
				$sql = "select * from appinfo {$condition->con()}";
			}else{
				$where = "A_Categoryid = '".$url_keyword."' and A_Class = '".$url_category."' ";
				$order = 'A_Appid';
				$condition = new Condition($where,$order);
				$sql = "select * from appinfo {$condition->con()}";
			}
		}else if(!$url_keyword){
			$where = "A_Class = '".$url_category."'";
			$order = 'A_Appid';
			$condition = new Condition($where,$order);
			if($url_category == ''){
				$sql = "select * from appinfo";
			}else{
				$sql = "select * from appinfo {$condition->con()}";
			}
		}
		
		if(isset($_POST['delete_app'])){
			$delete_appid = $_POST['app_id'];
			foreach($delete_appid as $key => $value){
				$sql_delete_app = "delete from appinfo where A_Appid = '$value'";
				$query_select_app = $mysqli->query($sql_delete_app);
				if($query_select_app){
					echo "<script>alert('删除成功')</script>";
				}else{
					echo "<script>alert('删除失败')</script>";
				}
			}
		}
		
		$query = $mysqli->query($sql);
		$total = $query->num_rows;
		$num = '25';
		$page = new Page($total,$num);


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<title>后台首页</title>
<style>
	body{ background:#e7e7e7; margin:0; padding:0;}
	#container{ width:980px; height:auto; position:relative; margin:0 auto;}
	#container #header{ width:980px; height:90px; position:relative; background:#000; line-height:90px;color:#fff; font-size:24px; text-align:center;}
	.left{width:250px; height:auto; position:relative; float:left;}
	.left table{width:248px; height:auto; position:relative; float:left; background:#fff;}
	.left table td{ height:20px; text-align:center;}
	.left table .selected{ background:#73abe3;}
	#content{ width:730px; height:100%; position:relative; float:left; margin:2px 0px;}
	#content .title{ width:720px; height:25px; position:relative; float:left; line-height:25px; font-size:18px; color:#fff; background:#000;}
	form{margin:20px auto; width:720px; height:auto; position:relative; float:left;}
	form .inpuarea{ width:360px; height:150px;}
	#content .app_class,#content .app_category{ width:100%; height:50px; position:relative; float:left; margin-top:3px;}
	#content .class_title,#content .category_title{ width:100%; height:15px; position:relative; float:left;}
	.app_class dt, .app_category dt{ width:auto; height:15px; position:relative; float:left; line-height:15px; font-size:14px; margin:0 3px;}
</style>
</head>
<body>
	<div id="container">
		<div id="header">
			818苹果站后台管理
		</div>
		<div class="left">
			<table>
				<tr><td style="background:#000000; color:#fff;">站点管理</td></tr>
				<tr><td><a href="admin_site_mangerment.php">全局管理</a></td></tr>
				<tr><td>静态页面管理</td></tr>
				<tr><td><a href="admin_link_mangerment.php?page=1">友情链接管理</a></td></tr>
				<tr><td><a href="admin_member_mangerment.php">会员管理</a></td></tr>
				<tr><td><a href="admin_tags_mangerment.php">标签管理</a></td></tr>
				<tr><td><a href="admin_search_mangerment.php">搜索管理</a></td></tr>
			</table>
			<table>
				<tr><td style="background:#000000; color:#fff;">文章管理</td></tr>
				<tr><td><a href="admin_category_mangerment.php">文章分类管理</a></td></tr>
				<tr><td><a href="admin_news_add.php">发布文章</a></td></tr>
				<tr><td><a href="admin_news_mangerment.php">文章管理</a></td></tr>
			</table>
			<table>
				<tr><td style="background:#000000; color:#fff;">应用管理</td></tr>
				<tr><td><a href="admin_appcate_mangerment.php">应用分类管理</a></td></tr>
				<tr><td><a href="admin_app_add.php">添加应用</a></td></tr>
				<tr><td class="selected"><a href="admin_app_mangerment.php">应用管理</a></td></tr>
                <tr><td><a href="admin_app_collection.php">应用采集</a></td></tr>
				<tr><td><a href="admin_app_collection_single.php">单应用采集</a></td></tr>
			</table>
		</div>
	<div id="content">
		<div class="class_title">搜索</div>
		<div class="app_class">
		<form action="admin_app_search.php" method="post">
			<dt><label>搜索APP</label></dt>
			<dt><input type="text" name="app_name" placeholder="请输入要搜索的APP名称" /></dt>
			<dt><input type="submit" name="search_app" value="搜索" /></dt>
		</form>
		</div>
		<div class="class_title">平台</div>
		<div class="app_class">
		
			<dt><a href="admin_app_mangerment.php?page=1">全部</a></dt>
			<dt><a href="admin_app_judgment.php?page=1&kw=&ca=0">IOS</a></dt>
			<dt><a href="admin_app_judgment.php?page=1&kw=&ca=1">越狱</a></dt>
		</div>
		<div class="category_title">类别</div>
        <div class="app_category">
        	
            	<dt><a href="admin_app_mangerment.php?page=1">全部</a></dt>
            <?php
            	$sql_appcategory = "select * from appcategoryinfo";
				$query_appcategory = $mysqli->query($sql_appcategory);
				while($result_appcategory = $query_appcategory->fetch_assoc()){
					$cid = $result_appcategory['AC_Categoryid'];
					$cname = $result_appcategory['AC_Categoryname'];
			?>
						<dt><a href="admin_app_judgment.php?page=1&kw=<?php echo $cid;?>&ca=<?php echo $url_category?>"><?php echo $cname;?></a></dt>
			<?php
				}
			?>
		<form name="form1" action="" method="post">
		<table id="all">
			<tr>会员列表</tr>
			<tr>
				<td>APP编号</td>
				<td>APP标题</td>
				<td>所属分类</td>
				<td>发布时间</td>
                <td>操作</td>
			</tr>
			<?php
			/*{$condition->con()} */
				$sql_app = $sql." {$page->limit_start()}";
				$query_app = $mysqli->query($sql_app);
				while($result_app = $query_app->fetch_array()){
			?>
			<tr>
				<td><input type="checkbox" name="app_id[]" value="<?php echo $result_app['A_Appid']?>" /><?php echo $result_app['A_Appid']?></td>
				<td><?php echo $result_app['A_Apptrackname']?></td>
				<td>
				<?php
					$categoryid = $result_app['A_Categoryid'];
					$sql_category_name = "select AC_Categoryname from appcategoryinfo where AC_Categoryid = '$categoryid'";
					$query_category_name = $mysqli->query($sql_category_name);
					$result_category_name = $query_category_name->fetch_assoc();
					echo $result_category_name['AC_Categoryname'];
				?>
				</td>
				<td><?php echo $result_app['A_Appdate']?></td>
				<td><a href="admin_app_edit.php?aid=<?php echo $result_app['A_Apptrackid'];?>">编辑</a></td>
			</tr>
			<?php
				}
			
			?>
			<tr>
                	<a style="margin:3px;" href="admin_app_judgment.php?page=1&kw=<?php echo $url_keyword;?>&ca=<?php echo $url_category;?>">首页</a>

                	<a style="margin:3px;" href="admin_app_judgment.php?page=<?php
																if($url_page ==1){
																	$url_prepage = $url_page;
																}else{
																	$url_prepage = $url_page-1;
																} 
																	echo $url_prepage;?>&kw=<?php echo $url_keyword;?>&ca=<?php echo $url_category;?>">上一页</a>

                	<?php echo $page->pageList(); ?>

                	<a style="margin:3px;" href="admin_app_judgment.php?page=<?php $pagenum = ceil($total/$num); 
																	if($url_page < $pagenum){
																		$url_page = $url_page+1;
																	}else{
																		$url_page = $pagenum;
																	}
																	echo $url_page;?>&kw=<?php echo $url_keyword;?>&ca=<?php echo $url_category;?>">下一页</a>

                	<a style="margin:3px;" href="admin_app_judgment.php?page=<?php echo $pagenum;?>&kw=<?php echo $url_keyword;?>&ca=<?php echo $url_category?>">尾页</a>

					<?php echo $page->pageTotal();?>             
            </tr>
			<tr>
				<td>
					<input type="checkbox" id="quan" name="quan" onclick="select_all()" />全选
					<input type="submit" name="delete_app" value="删除" onclick="del()" /> 
				</td>
			</tr>
		</table>
        <table id="condition" style="display:none;">
        
        </table>
		</form>
	</div>
</body>
<script>
	function select_all(){
		var length = document.form1.elements.length;
		var i = 0;
		for(i=0;i<length;i++){
			var checked = document.form1.elements[i];
			if(checked.name != 'quan'){
				if(document.getElementById("quan").checked != false){
					checked.checked = true;
				}else{
					checked.checked = false;
				}
			}
		}
	}
	function del(){
		var length = document.form1.elements.length;
		var i = 0;
		for(i=0;i<length;i++){
			var checked = document.form1.elements[i];
			if(checked.name != 'quan'){
				if(checked.checked == true){
					alert(checked.name+checked.value);
				}
			}
		}
	}
	$(document).ready(function(){
		$("table").find("td").click(function(){
			src = $(this).attr("data-option-value");
			if(!$(this).hasClass("selected")){
				$("table").find("td").removeClass("selected");
				$(this).addClass("selected");
				$("iframe").attr("src",src);
			}			
		});
	});
/*	$(document).ready(function(){
		$(".app_category").find("dt a").click(function(){
			var data = $(this).attr("data-filter");
			$("table#all").hide();
			$.post("judgment.php?page=1",{data:data},function(data){$("table#condition").show().html(data);})
		});
	});*/
//	$(document).ready(function(){
//		var selected = ;
//		if(!selected){			
//			$(".app_class").find("dt a").eq(1).addClass("selected");
//		}else{
//			var num = selected+1;
//			$(".app_class").find("dt a").eq(num).addClass("selected");
//		}
//	});
</script>
</html>
<?php
	}else{
		echo "<script>你想干嘛！登录先！！！</script>";
		echo "<meta http-equiv=\"refresh\" content=\"1; url='admin_login.php' />";
	}

?>